undefined method `key?' for nil:NilClass when using MongoMapper
Posted
by
Radek Slupik
on Stack Overflow
See other posts from Stack Overflow
or by Radek Slupik
Published on 2012-06-12T16:26:11Z
Indexed on
2012/06/12
16:40 UTC
Read the original article
Hit count: 253
I set up a new Rails application by following these instructions. I generated a new controller and added resources :tickets
to the routes file.
Hexapoda::Application.routes.draw do
resources :tickets
end
This is the controller (`/app/controllers/tickets_controller.rb').
class TicketsController < ApplicationController
def index
@tickets = Ticket.all
end
end
I then added a new model Ticket
in /app/models/ticket.rb
.
class Ticket
include MongoMapper::Document
key :summary, String, :required => true
end
Here's the view (/app/views/index.html.erb
):
<h1>Tickets#index</h1>
<p>Find me in app/views/tickets/index.html.erb</p>
Now when I go to /tickets
in my browser, I get an error message.
NoMethodError in TicketsController#index
undefined method `key?' for nil:NilClass
I have no idea what's going on. What could be the problem? I'm using Rails 3.2.5 and MongoMapper 0.11.1.
© Stack Overflow or respective owner